﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using DatabaseSchemaReader;
using DatabaseSchemaReader.DataSchema;

namespace Happy.Edge.DatabaseSchemaReader.Extentions
{
    public static class DatbaseTableExtentions
    {
        public static object ToDynamic(this DatabaseTable table)
        {
            return new
            {
                name = table.Name,
                isPlural = Utils.IsPlural(table.Name),
                isSingular = Utils.IsSingular(table.Name),
                plural = Utils.Pluralize(table.Name),
                singular = Utils.Singularize(table.Name),
                owner = table.SchemaOwner,
                foreignKeys = table.ForeignKeys.Select(foreignKey => foreignKey.ToDynamic()).ToList(),
                columns = table.Columns.Select(column => column.ToDynamic()).ToList()
            };
        }
    }
}
